from pushByFeishu import FeiShuMSG
import mysql.connector

webhook = f'https://open.feishu.cn/open-apis/bot/v2/hook/d5cbd5f7-333d-4d34-a9ae-4578dd8ad9a8'

def mysql_message():
    # 配置数据库连接信息
    config = {
        'user': 'root',
        'password': 'Hello123!',
        'host': '101.43.233.179',
        # 'host': '127.0.0.1',
        'database': 'remind',
        'raise_on_warnings': True
    }

    final_message = ""

    try:
       # 建立数据库连接
       cnx = mysql.connector.connect(**config)
       cursor = cnx.cursor()

       # 执行查询语句
       query = "SELECT * FROM daily"
       cursor.execute(query)

       # 获取查询结果
       for (id, content) in cursor:  # 根据你的表结构替换column1, column2, column3,...
          print(f"Column1: {id}, Column2: {content}")  # 同样替换输出格式
          final_message+= "" + content+"\n"
          final_message+= "-----------\n"

    except mysql.connector.Error as err:
       print(f"Error: {err}")
    finally:
       # 关闭游标和连接
      cursor.close()
      cnx.close()
      print("MySQL connection is closed")

      return final_message

if __name__ == "__main__":
    msg = mysql_message()

    send_msg=msg
    message_text = send_msg
    feishu = FeiShuMSG(token=webhook, text=message_text)
    feishu.send_msg_info()

